(function () {
    var serverData = {};
    var	serverTable;
    var sel = document.getElementById('sel');
	var date = new Date();
	for(var j=2;j>=0;j--){
		var opt = document.createElement("option");
		opt.value = date.getFullYear()+j;
		opt.innerHTML = (date.getFullYear()+j);
		sel.appendChild(opt);
		if(j==0){
			opt.selected=true
		}
	}
	for(var i=0;i<5;i++)
	{
		var opt = document.createElement("option");
		opt.value = date.getFullYear()-i-1;
		opt.innerHTML = (date.getFullYear()-i-1);
		sel.appendChild(opt);
	}
	var sele = document.getElementById('sele');
	for(var k=1;k<=12;k++){
		var a  = k;
		if(a<10){
			a = "0"+a;
		}
		var opt = document.createElement("option");
		opt.value = a;
		opt.innerHTML = (a);
		sele.appendChild(opt);
		if(date.getMonth()+1==a){
			opt.selected=true
		}
	}
	/**
	 * 初始化日期1
	 */
	if(date.getMonth()+1<10){//月份小于10在月份前面加0
		var thismonth = "0"+(date.getMonth()+1)
		var lastmonth = "0"+(date.getMonth())
	}else{
		var thismonth = date.getMonth()+1
		var lastmonth = date.getMonth()
	}
	var dateThisMonth = date.getFullYear()+""+thismonth//本月
	if(date.getMonth()+1 == 1){//上月
		//如果为1月份上月则是去年12月份
		var dateLastMonth = (date.getFullYear()-1)+"12"//
	}else{
		var dateLastMonth = date.getFullYear()+""+lastmonth
	}
	var dateLastYear = (date.getFullYear()-1)+""+thismonth//去年
	
	
  //查询1
    jQuery('#search-btn').on('click', function() {
    	var year = jQuery('#sel').val()
    	var month = jQuery('#sele').val()
    	var thismonth = year+""+month;
    	var lastmonth = "";
    	if(month-1 <10){
    		if(month == "01"){
    			lastmonth = (year-1)+"12"
    		}else{
    			lastmonth = year+"0"+(month-1)
    		}
    	}else{
    		lastmonth = year+""+(month-1)
    	}
    	var lastyear = (year-1)+""+month
    	jQuery.ajax({
			type : 'get',
			url : window.rootPath+ '/ui/payIncomeAnalysis/getMyTrance',
			data :{
				'dateThisMonth':thismonth,
				'dateLastMonth':lastmonth,
				'dateLastYear':lastyear
			},
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function(data) {
				valuation(data);
			}
		});
	});
    jQuery(document).ready(function () {
    	jQuery.ajax({
			type : 'get',
			url : window.rootPath+ '/ui/payIncomeAnalysis/getMyTrance',
			data :{
				'dateThisMonth':dateThisMonth,
				'dateLastMonth':dateLastMonth,
				'dateLastYear':dateLastYear
			},
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function(data) {
				valuation(data);
			}
		});
    });
})();

function valuation(data){
	var ctdq = 0;
	var xsdq = 0;
	var ctdqysk = 0;
	var xsdqysk = 0;
	/**
	 * 本月
	 */
	for(var i=0;i<data.dateThisMonth.length;i++){
		if(data.dateThisMonth[i].superior == "成套处"){
			ctdq = data.dateThisMonth[i].nNowMonthGetPaySum;
			ctdqysk = data.dateThisMonth[i].nNowYSSum;
			document.getElementById("dqct").innerHTML = data.dateThisMonth[i].nNowMonthGetPaySum;
			document.getElementById("ctdqysk").innerHTML = data.dateThisMonth[i].nNowYSSum;
		}else if(data.dateThisMonth[i].superior == "销售处"){
			xsdq = data.dateThisMonth[i].nNowMonthGetPaySum;
			xsdqysk = data.dateThisMonth[i].nNowYSSum
			document.getElementById("dqxs").innerHTML = data.dateThisMonth[i].nNowMonthGetPaySum;
			document.getElementById("xsdqysk").innerHTML = data.dateThisMonth[i].nNowYSSum;
		}
	}
	if (ctdq !== null && ctdq !== undefined && ctdq !== "" && ctdq!==0) { 
		if (ctdqysk !== null && ctdqysk !== undefined && ctdqysk !== "" && ctdqysk !==0) { 
			document.getElementById("cthkl").innerHTML = (ctdq/ctdqysk).toFixed(2)*100+"%";
		}
	} 
	if (xsdq !== null && xsdq !== undefined && xsdq !== "" && xsdq!==0) { 
		if (xsdqysk !== null && xsdqysk !== undefined && xsdqysk !== "" && xsdqysk!==0) { 
			document.getElementById("xshkl").innerHTML = (xsdq/xsdqysk).toFixed(2)*100+"%";
		}
	} 
	document.getElementById("dqhkhj").innerHTML = ctdq+xsdq;
	document.getElementById("dqyskhj").innerHTML = ctdqysk+xsdqysk;
	var a = ctdq+xsdq;
	var b = ctdqysk+xsdqysk;
	if ((ctdq+xsdq) !== null && (ctdq+xsdq) !== undefined && (ctdq+xsdq) !== "" && (ctdq+xsdq)!==0) { 
		if ((ctdqysk+xsdqysk) !== null && (ctdqysk+xsdqysk) !== undefined && (ctdqysk+xsdqysk) !== "" && (ctdqysk+xsdqysk)!==0) { 
			document.getElementById("dqhjhkl").innerHTML = (a/b).toFixed(2)*100+"%";
		}
	}
	
	/**
	 * 上年
	 */
	var snctdqhk = 0;
	var snxsdqhk = 0;
	var snctdqysk = 0;
	var sncxsqysk = 0;
	for(var j=0;j<data.dateLastYear.length;j++){
		if(data.dateLastMonth[j] == "成套处"){
			syctdqhk = data.dateLastYear[j].nNowMonthGetPaySum;
			snctdqysk = data.dateLastYear[j].nNowYSSum;
			document.getElementById("snctdqhk").innerHTML = data.dateLastYear[j].nNowMonthGetPaySum;
			document.getElementById("snctdqysk").innerHTML = data.dateLastYear[j].nNowYSSum;
		}else if(data.dateLastMonth[j] == "销售处"){
			syxsdqhk = data.dateLastYear[j].nNowYSSum;
			sncxsqysk = data.dateLastYear[j].nNowYSSum;
			document.getElementById("snxsdqhk").innerHTML = data.dateLastYear[j].nNowMonthGetPaySum;
			document.getElementById("sncxsqysk").innerHTML = data.dateLastYear[j].nNowYSSum;
		}
	}
	document.getElementById("snctdqhj").innerHTML = snctdqhk+snxsdqhk;
	document.getElementById("snxsdqhhj").innerHTML = snctdqysk+sncxsqysk;
	if (snctdqhk !== null && snctdqhk !== undefined && snctdqhk !== "" && isNaN(snctdqhk) == false && snctdqhk!==0) { 
		if (snctdqysk !== null && snctdqysk !== undefined && snctdqysk !== "" && isNaN(snctdqysk) == false && snctdqhk!==0) { 
			document.getElementById("sncthkl").innerHTML = (snctdqhk/snctdqysk).toFixed(2)*100+"%";
			
		}
	} 
	if (snxsdqhk !== null && snxsdqhk !== undefined && snxsdqhk !== "" && isNaN(snxsdqhk) == false && snxsdqhk!==0) { 
		if (sncxsqysk !== null && sncxsqysk !== undefined && sncxsqysk !== "" && isNaN(sncxsqysk) == false && sncxsqysk!==0) { 
			document.getElementById("snxshkl").innerHTML = (snxsdqhk/sncxsqysk).toFixed(2)*100+"%";
			
		}
	} 
	if ((snctdqhk+snxsdqhk) !== null && (snctdqhk+snxsdqhk) !== undefined && (snctdqhk+snxsdqhk) !== "" && isNaN((snctdqhk+snxsdqhk)) == false && (snctdqhk+snxsdqhk)!==0) { 
		if ((snctdqysk+sncxsqysk) !== null && (snctdqysk+sncxsqysk) !== undefined && (snctdqysk+sncxsqysk) !== "" && isNaN((snctdqysk+sncxsqysk)) == false && (snctdqysk+sncxsqysk)!==0) { 
			document.getElementById("snxshkl").innerHTML = ((snctdqhk+snxsdqhk)/(snctdqysk+sncxsqysk)).toFixed(2)*100+"%";
		}
	} 
	
	/**
	 * 上月
	 */
	var syctdqhk = 0;//上月成套当期回款
	var syxsdqhk = 0;//上月销售当期回款
	var syctyshk = 0;//上月成套应收回款
	var syxsyshk = 0;//上月销售应收回款
	for(var k=0;k<data.dateLastMonth.length;k++){
		if(data.dateLastMonth[j] == "成套处"){
			syctdqhk = data.dateLastMonth[j].nNowMonthGetPaySum;
			document.getElementById("syctdqhk").innerHTML = data.dateLastMonth[j].nNowMonthGetPaySum;
			syctyshk = data.dateLastMonth[j].nNowYSSum;
			document.getElementById("syctdqhk").innerHTML = data.dateLastMonth[j].nNowYSSum;
		}else if(data.dateLastMonth[j] == "销售处"){
			syxsdqhk = data.dateLastMonth[j].nNowMonthGetPaySum;
			document.getElementById("syxsdqhk").innerHTML = data.dateLastMonth[j].nNowMonthGetPaySum;
			syxsyshk = data.dateLastMonth[j].nNowYSSum;
			document.getElementById("syxsyshk").innerHTML = data.dateLastMonth[j].nNowYSSum;
		}
	}
	document.getElementById("sydqhj").innerHTML = syctdqhk+syxsdqhk;
	document.getElementById("syyshj").innerHTML = syctyshk+syxsyshk;
	if (syctdqhk !== null && syctdqhk !== undefined && syctdqhk !== "" && isNaN(syctdqhk) == false && syctdqhk!==0) { 
		if (syxsdqhk !== null && syxsdqhk !== undefined && syxsdqhk !== "" && isNaN(syxsdqhk) == false && syxsdqhk!==0) { 
			document.getElementById("sycthkl").innerHTML = (syctdqhk/syxsdqhk).toFixed(2)*100+"%";
		}
	}
	if (syctyshk !== null && syctyshk !== undefined && syctyshk !== "" && isNaN(syctyshk) == false && syctyshk!==0) { 
		if (syxsyshk !== null && syxsyshk !== undefined && syxsyshk !== "" && isNaN(syxsyshk) == false && syxsyshk!==0) { 
			document.getElementById("syxshkl").innerHTML = (syctyshk/syxsyshk).toFixed(2)*100+"%";
		}
	}
	if ((syctdqhk+syxsdqhk) !== null && (syctdqhk+syxsdqhk) !== undefined && (syctdqhk+syxsdqhk) !== "" && isNaN((syctdqhk+syxsdqhk)) == false && (syctdqhk+syxsdqhk)!==0) { 
		if ((syctyshk+syxsyshk) !== null && (syctyshk+syxsyshk) !== undefined && (syctyshk+syxsyshk) !== "" && isNaN((syctyshk+syxsyshk)) == false && (syctyshk+syxsyshk)!==0) { 
			document.getElementById("syhkl").innerHTML = ((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2)*100+"%";
		}
	}
	//合计同比
	if ((a/b).toFixed(2)-(snctdqhk+snxsdqhk) !== null && (a/b).toFixed(2)-(snctdqhk+snxsdqhk) !== undefined && (a/b).toFixed(2)-(snctdqhk+snxsdqhk) !== "" && isNaN((a/b).toFixed(2)-(snctdqhk+snxsdqhk)) == false && (a/b).toFixed(2)-(snctdqhk+snxsdqhk)!==0) { 
		if ((snctdqhk+snxsdqhk)/(snctdqysk+sncxsqysk) !== null && (snctdqhk+snxsdqhk)/(snctdqysk+sncxsqysk) !== undefined && (snctdqhk+snxsdqhk)/(snctdqysk+sncxsqysk) !== "" && isNaN((snctdqhk+snxsdqhk)/(snctdqysk+sncxsqysk)) == false && (snctdqhk+snxsdqhk)/(snctdqysk+sncxsqysk)!==0) { 
			document.getElementById("hjtb").innerHTML = (((a/b).toFixed(2)-(snctdqhk+snxsdqhk)/(snctdqysk+sncxsqysk))/(snctdqhk+snxsdqhk)/(snctdqysk+sncxsqysk)).toFixed(2)+"%";
		}
	}
	//成套同比
	if (((ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2)) !== null && ((ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2)) !== undefined && ((ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2)) !== "" && isNaN(((ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2))) == false && ((ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2))!==0) { 
		if ((snctdqhk/snctdqysk).toFixed(2) !== null && (snctdqhk/snctdqysk).toFixed(2) !== undefined && (snctdqhk/snctdqysk).toFixed(2) !== "" && isNaN((snctdqhk/snctdqysk).toFixed(2)) == false && (snctdqhk/snctdqysk).toFixed(2)!==0) { 
			document.getElementById("cttb").innerHTML = (((ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2))/(snctdqhk/snctdqysk).toFixed(2))*100+"%";
		}
	}
	//销售同比
	if ((xsdq/xsdqysk).toFixed(2)-(snxsdqhk/sncxsqysk).toFixed(2) !== null && (xsdq/xsdqysk).toFixed(2)-(snxsdqhk/sncxsqysk).toFixed(2) !== undefined && (xsdq/xsdqysk).toFixed(2)-(snxsdqhk/sncxsqysk).toFixed(2) !== "" && isNaN((xsdq/xsdqysk).toFixed(2)-(snxsdqhk/sncxsqysk).toFixed(2)) == false && (xsdq/xsdqysk).toFixed(2)-(snxsdqhk/sncxsqysk).toFixed(2)!==0) { 
		if ((snxsdqhk/sncxsqysk).toFixed(2) !== null && (snxsdqhk/sncxsqysk).toFixed(2) !== undefined && (snxsdqhk/sncxsqysk).toFixed(2) !== "" && isNaN((snxsdqhk/sncxsqysk).toFixed(2)) == false && (snxsdqhk/sncxsqysk).toFixed(2)!==0) { 
			document.getElementById("xstb").innerHTML = ((xsdq/xsdqysk).toFixed(2)-(snxsdqhk/sncxsqysk).toFixed(2))/(snxsdqhk/sncxsqysk).toFixed(2)*100+"%";
		}
	}
	//合计环比
	if ((a/b).toFixed(2)-((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2) !== null && (a/b).toFixed(2)-((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2) !== undefined && (a/b).toFixed(2)-((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2) !== "" && isNaN((a/b).toFixed(2)-((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2)) == false && (a/b).toFixed(2)-((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2)!==0) { 
		if (((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2) !== null && ((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2) !== undefined && ((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2) !== "" && isNaN(((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2)) == false && ((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2)!==0) { 
			document.getElementById("hjhb").innerHTML = ((a/b).toFixed(2)-((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2))/((syctdqhk+syxsdqhk)/(syctyshk+syxsyshk)).toFixed(2)*100+"%";
		}
	}
	//成套环比
	if ((ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2) !== null && (ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2) !== undefined && (ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2) !== "" && isNaN((ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2)) == false && (ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2)!==0) { 
		if ((snctdqhk/snctdqysk).toFixed(2) !== null && (snctdqhk/snctdqysk).toFixed(2) !== undefined && (snctdqhk/snctdqysk).toFixed(2) !== "" && isNaN((snctdqhk/snctdqysk).toFixed(2)) == false && (snctdqhk/snctdqysk).toFixed(2)!==0) { 
			document.getElementById("cthb").innerHTML = ((ctdq/ctdqysk).toFixed(2)-(snctdqhk/snctdqysk).toFixed(2))/(snctdqhk/snctdqysk).toFixed(2)*100+"%";
		}
	}
	//销售环比
	if ((xsdq/xsdqysk).toFixed(2)-(syctyshk/syxsyshk).toFixed(2) !== null && (xsdq/xsdqysk).toFixed(2)-(syctyshk/syxsyshk).toFixed(2) !== undefined && (xsdq/xsdqysk).toFixed(2)-(syctyshk/syxsyshk).toFixed(2) !== "" && isNaN((xsdq/xsdqysk).toFixed(2)-(syctyshk/syxsyshk).toFixed(2)) == false && (xsdq/xsdqysk).toFixed(2)-(syctyshk/syxsyshk).toFixed(2)!==0) { 
		if ((syctyshk/syxsyshk).toFixed(2) !== null && (syctyshk/syxsyshk).toFixed(2) !== undefined && (syctyshk/syxsyshk).toFixed(2) !== "" && isNaN((syctyshk/syxsyshk).toFixed(2)) == false && (syctyshk/syxsyshk).toFixed(2)!==0) { 
			document.getElementById("xshb").innerHTML = ((xsdq/xsdqysk).toFixed(2)-(syctyshk/syxsyshk).toFixed(2))/(syctyshk/syxsyshk).toFixed(2)*100+"%";
		}
	}
}
